/*
 * @Descripttion: 
 * @version: 
 * @Author: yuanliutech
 * @Date: 2025-03-18 10:37:26
 * @LastEditors: yuanliutech@lwj
 * @LastEditTime: 2025-03-18 11:13:48
 */
import {
    showMsg
} from '../../utils/config.js'
import {
    reqUserCancel
} from '../../request/api'
var cancelTimer = null //确定注销定时
Component({

    /**
     * 组件的属性列表
     */
    properties: {
        show: false,
    },

    options: {
        addGlobalClass: true
    },

    data: {
        cancelCount: 7,
    },

    observers: {
        show(val) {
            if (!val) return
            this.countDownFoo()
        }
    },

    methods: {


        // 注销账号请求
        countDownFoo() {
            this.setData({
                cancelCount: 7
            })
            let {
                cancelCount
            } = this.data
            cancelTimer = setInterval(() => {
                cancelCount -= 1
                if (cancelCount < 0) {
                    clearInterval(cancelTimer);
                    return
                } else {
                    this.setData({
                        cancelCount
                    })
                }
            }, 1000)

        },
        // 取消注销
        cancelCancelAccount() {
            clearInterval(cancelTimer);
            cancelTimer = null

            this.triggerEvent('handleAction', {
                show: false,
                msg: 'cancel',
            });
        },
        // 确定注销
        async cancelAccountConfirm() {
            clearInterval(cancelTimer);
            cancelTimer = null

            const res = await reqUserCancel()
            if (res.code !== 20000) return showMsg(res.message)
            showMsg("已注销")

            this.triggerEvent('handleAction', {
                show: false,
                msg: 'confirm',
            });
        },


    }
})